import * as actionTypes from '../constants/header';
import axios from 'axios';
import {fromJS} from "immutable";

const changeList = (data) => ({
    type: actionTypes.CHANGE_LIST,
    data: fromJS(data),
    totalPage: Math.ceil(data.length / 10)
});

export const searchFocus = () => ({
    type: actionTypes.SEARCH_FOCUS
});

export const searchBlur = () => ({
    type: actionTypes.SEARCH_BLUR
});

export const mouseEnter = () => ({
    type: actionTypes.MOUSE_ENTER
});

export const mouseLeave = () => ({
    type: actionTypes.MOUSE_LEAVE
});

export const changeListPage = (page) => ({
    type: actionTypes.CHANGE_LIST_PAGE,
    page: page
});

export const getRecommendList = () => {
    return (dispatch) => {
        axios.get('/api/headerList.json').then(res => {
            let data = res.data;
            dispatch(changeList(data.data));
        }).catch(() => {
            console.log('Error');
        })
    }
};